package org.groupg.practice;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.TimeInterval;
import cn.hutool.core.lang.Console;
import com.github.javafaker.Faker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.SQLException;
import java.util.Date;
import java.util.Locale;

public class SQLDemo {
    public static String sql = "insert into sys_user(id, username, password, userid, gender, email, phone, address, birthday) VALUES (?,?,?,?,?,?,?,?,?)";
    static Logger log = LoggerFactory.getLogger(SQLDemo.class);

    public static void main(String[] args) throws SQLException {
        Faker faker = new Faker(new Locale("zh-CN"));
//        System.out.println("当前时间:"+System.currentTimeMillis());

        MainDataSource.execUpdate(statement -> {
            TimeInterval interval = new TimeInterval();
            for (int i = 0; i < 1_000_000; i++) {
                int id = i+1;
                String username = faker.name().username();
                String password = faker.name().username();
                String userid = faker.name().username();
                int gender = faker.random().nextInt(2);
                String email = faker.internet().emailAddress();
                String phone = faker.phoneNumber().phoneNumber();
                String address = faker.address().city();
                Date birthday = faker.date().birthday();
                try {
                    statement.execute(" insert into sys_user(id, username, password, userid, gender, email, phone, address, birthday) " +
                            " VALUES (" + id + ",'"+username+"','"+password+"','"+userid+"','"+gender+"','"+email+"','"+phone+"','"+address+"',now()) ");
                } catch (SQLException e) {
                    e.printStackTrace();
                }
                log.debug("第{}次消耗：{}",id,DateUtil.formatBetween(interval.intervalRestart()));
            }

        });
        System.out.println("结束时间:"+System.currentTimeMillis());

    }
}
